package model.bo;

import java.util.List;

import model.bean.Aluno;
import model.bean.Indicacao;
import model.bean.Matricula;
import model.bean.Turma;
import model.persistencia.dao.HibernateUtil;
import model.persistencia.dao.IndicacaoDAO;

public class IndicacaoBO {
	private IndicacaoDAO indicacaoDao;
	
	public IndicacaoBO(){
		indicacaoDao = new IndicacaoDAO();
	}
	
	private HibernateUtil getTransaction(){
		return HibernateUtil.getInstance();
	}
	
	public Indicacao incluir(Indicacao indicacao) throws Exception{
		indicacao.setId(indicacao.getMatricula().getId());
		getTransaction().startTransaction();
		try{
			indicacao = indicacaoDao.save(indicacao);
			getTransaction().commitTransaction();
			return indicacao;
		}catch (Exception e) {
			getTransaction().rollbackTransaction();
			throw e;
		}
	}
	
	public Indicacao consultar(Matricula matricula) throws Exception{
		Indicacao indicacao = null;
		getTransaction().startTransaction();
		try{
			indicacao = indicacaoDao.load(matricula.getId());
			getTransaction().commitTransaction();
			return indicacao;
		}catch (Exception e) {
			getTransaction().rollbackTransaction();
			throw e;
		}
	}
	
	public Indicacao alterar(Indicacao indicacao) throws Exception{
		getTransaction().startTransaction();
		try{
			indicacao = indicacaoDao.merge(indicacao);
			getTransaction().commitTransaction();
			return indicacao;
		}catch (Exception e) {
			getTransaction().rollbackTransaction();
			throw e;
		}
	}
	
	public void excluir(Indicacao indicacao) throws Exception{
		getTransaction().startTransaction();
		try{
			indicacaoDao.delete(indicacao);
			getTransaction().commitTransaction();
		}catch (Exception e) {
			getTransaction().rollbackTransaction();
			throw e;
		}
	}
	
	public List<Indicacao> getIndicacoes(Turma turma){
		return indicacaoDao.getIndicacoes(turma);
	}
	
}
